/**
 * @Date 2023-02-24 13:46:57
 * @Remark
 */

// react
import React, { useEffect } from "react";
// lib
import { Modal, Form, Input } from "antd";
// components & widget
// style
// config
import { MODAL_STYLE } from "project/config";
import { INPUT_REQUIRED_RULE } from "project/validRules";
// script & methods & public
// store
import { observer } from "mobx-react";
import { state } from "./state";
// import { updateDeliveryRecordOrderType } from "./controller";
// controller
// interface
// 其它

function AbnormalOrderEditModal() {
  const [form] = Form.useForm();

  const show = state.abnormalOrderEditModalShow;
  const title = "异常订单处理";

  useEffect(() => {
    if (show) {
      form.resetFields();
    }
    if (state.abnormalOrderEditInfo) {
      const info = state.abnormalOrderEditInfo;
      form.setFieldsValue({
        ...info,
      });
    }
    return () => {
      //
    };
  }, [form, show]);

  const handleCancel = () => {
    state.abnormalOrderEditModal = false;
  };

  const handleOk = async () => {
    try {
      const result = await form.validateFields();
      // if (state.abnormalOrderEditInfo) {
      //   updateDeliveryRecordOrderType(result, state.abnormalOrderEditInfo.id);
      // }
    } catch (error) {
      //
    }
  };

  return (
    <Modal
      title={title}
      open={show}
      onCancel={handleCancel}
      onOk={handleOk}
      destroyOnClose
      maskClosable
      forceRender
      okButtonProps={{
        loading: state.editModalLoading,
      }}
    >
      <Form {...MODAL_STYLE.FORM_4_18} form={form}>
        <Form.Item name="id" label="配送单号" rules={[INPUT_REQUIRED_RULE]}>
          <Input bordered={false} readOnly />
        </Form.Item>
        <Form.Item name="orderSn" label="订单号" rules={[INPUT_REQUIRED_RULE]}>
          <Input bordered={false} readOnly />
        </Form.Item>
        <Form.Item name="deliveryUserName" label="配送员" rules={[INPUT_REQUIRED_RULE]}>
          <Input bordered={false} readOnly />
        </Form.Item>
        <Form.Item name="abnormalCause" label="异常原因" rules={[INPUT_REQUIRED_RULE]}>
          <Input.TextArea
            allowClear
            showCount
            maxLength={200}
            style={{ height: 120 }}
          />
        </Form.Item>
      </Form>
    </Modal>
  );
}

export default observer(AbnormalOrderEditModal);
